<template>
  <svg :class="svgClass" v-bind="$attrs" :style="{ color, fontSize: size }">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script setup lang="ts">
type Props = {
  name: string;
  color?: string;
  size?: string | number;
};
const props = withDefaults(defineProps<Props>(), {
  color: "",
  size: "",
});
const iconName = computed(() => `#icon-${props.name}`);
const svgClass = computed(() => {
  if (props.name) {
    return `svg-icon icon-${props.name}`;
  }
  return "svg-icon";
});
</script>

<style>
.svg-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: middle;
}
</style>
